package com.mengwen.backstage.mapper;



import com.mengwen.backstage.pojo.Partner;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface PartnerMapper {

    @Select("SELECT * FROM partner WHERE openid = #{openid}")
    public Partner findByOpenid(String openid);

    @Select("SELECT * FROM partner WHERE account_number = #{accountNumber} AND password = #{password}")
    Partner login(String accountNumber, String password);

    @Update("UPDATE partner SET openid = #{openid} WHERE account_number = #{accountNumber} AND password = #{md5Password}")
    Integer updateOpenidByAccountNumberAndPassword(String openid, String accountNumber, String md5Password);

    @Select("SELECT * FROM partner WHERE account_number = #{accountNumber} AND password = #{md5Password}")
    Partner findByAccountNumberAndPassword(String accountNumber, String md5Password);

    @Update("UPDATE partner SET state = 1 WHERE openid = #{openid}")
    Integer updateStateByOpenid(String openid);

    @Select("SELECT state FROM partner WHERE openid = #{openid}")
    Integer findStateByOpenid(String openid);

    @Select("SELECT state FROM partner WHERE account_number = #{accountNumber}")
    Integer findStateByAccountNumber(String accountNumber);

    @Update("UPDATE partner SET state = 1 WHERE account_number = #{accountNumber}")
    Integer updateStateByAccountNumber(String accountNumber);

    @Update("UPDATE partner SET money = 0 WHERE openid = #{openid}")
    Integer updateMoneyByopenid(String openid);

    @Update("UPDATE partner SET money = money + #{addmoney} WHERE unionid = #{inviterUnionid}")
    Integer updateMoneyByunionid(String inviterUnionid, Double addmoney);

    @Update("UPDATE partner SET teammate_count = teammate_count + 1 WHERE unionid = #{inviterUnionid}")
    Integer addTeammateCountByUnionid(String inviterUnionid);

    @Update("UPDATE partner SET publish_count = publish_count + 1 WHERE unionid = #{inviterUnionid}")
    Integer addPublishCountByUnionid(String inviterUnionid);
}
